home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-13 | 1.8 KB | 87 lines | [TEXT/CWIE] |
- #include "SortPicts.h"
-
-
-
- void SortPicts::UseSortData( void)
- {
- sortPixmap = GetGWorldPixMap( sortGWorld);
-
- LockPixels( sortPixmap);
-
- sortPixels = (SortPixelPtr) GetPixBaseAddr( sortPixmap);
-
- if ( !coplandTask )
- {
- HLock( (Handle) sortHandle);
-
- sortData = *sortHandle;
- }
- }
-
- void SortPicts::UnuseSortData( void)
- {
- if ( !coplandTask ) {
- HUnlock( (Handle) sortHandle);
-
- UnlockPixels( sortPixmap);
- }
- }
-
-
-
-
- /*
- * RandomPixel
- * -----------
- *
- *
- * RandomPixel will return a random number, x, between 0 ≤ x < N
- * where N is the number of pixels in the image.
- */
- long SortPicts::RandomPixel( void) // Return a # between 0 <= x < max
- {
- return Random( N);
- }
-
- // need our oun random routine since we can't call the toolbox random routine from an MP task.
-
- /*
- * Random
- * ------
- * Usage: r = Random( num)
- *
- * Random will return a random number, r, 0 ≤ r < num
- */
- long SortPicts::Random( long num)
- {
- long randomNum = 0x7FFFFFFF; // The ultimate long
- long tempN;
- short numNBits;
- short numShiftBits, numRandomBits;
-
- // Random Number Initialization
- tempN = num;
- numNBits = 1; // Using the additive conguential method (Random numbers)
- while (tempN >>= 1) // Count the number of bits required to hold N
- ++numNBits; // example: to hold 0x37 requires 6 bits (0-3F)
-
- numRandomBits = 31;
- numShiftBits = numRandomBits - numNBits;
-
- if( randomSeed < 0)
- randomSeed = -randomSeed;
-
- while( randomNum >= num || randomNum < 0)
- {
- // RandomNum generator
- randomNum = randomSeed = (randomSeed & 1) ^ ((randomSeed & (1L << 28)) >> 28)
- ? (randomSeed >> 1) : (randomSeed >> 1) | 0x40000000;
- // This next line "mixes" some of the upper bits with the lower bits
- randomNum = randomNum & (0xFFFFFFFF >> numShiftBits);
- // randomNum = (randomNum >> numShiftBits) ^ (randomNum & (0x7FFFFFFF >> numShiftBits));
- }
-
- return randomNum;
- }
-
-